﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Chromos;
using Chromos.ActionEngine;
using Chromos.Actors;
#endregion

namespace Chromos.AIEngine
{
	public class PlayerAIEngine : ActorAIEngine
	{
		public PlayerAIEngine(Actor actor, string aggressiveSetting, int radius)
            : base(actor, aggressiveSetting, radius)
		{
		}

		private int currentAttackIndex = 0;
		private int numAttacks = 2;

        public override void kill()
        {
            if (!getDying())
            {
                setDying();
                actor.getActionEngine().stopAllActionsWithForce();
                actor.getActionEngine().playAction(ActionType.Death, 0);
            }
        }

		public void controllerIdle()
		{
			if (!getIdle() && !getDying() && !getAttacking() && !getJumping())
			{
				setIdle();
			}
			if (!getDying() && !getJumping())
			{
				actor.getActionEngine().stopAllActions();
				//actor.getActionEngine().playAction(ActionType.Idle, 0);
			}
		}

        public void controllerUp()
        {
			if (!getJumping() && !getDying())
            {
                setJumping();
                actor.getActionEngine().playAction(ActionType.Movement, 2);
            }
        }

		public void controllerMoveLeft()
		{
			if (!getMovingLeft() && !getDying())
			{
				setMovingLeft();
				actor.getActionEngine().stopAllActions();
				actor.getActionEngine().playAction(ActionType.Movement, 0);
			}
		}

		public void controllerMoveRight()
		{
			if (!getMovingRight() && !getDying())
			{
				setMovingRight();
				actor.getActionEngine().stopAllActions();
				actor.getActionEngine().playAction(ActionType.Movement, 1);
			}
		}

		public void controllerShoot()
		{
			if (getDead())
			{
				actor.setAlive();
				actor.health += 100;
			}
			if (!getAttacking() && !getDying())
			{
				if(actor.getFacing() == FACING.RIGHT)
					actor.getActionEngine().playAction(ActionType.Attack, this.currentAttackIndex*2+1);
				else
					actor.getActionEngine().playAction(ActionType.Attack, this.currentAttackIndex*2);
			}
		}

		public void controllerSwitchWeapons()
		{
			this.currentAttackIndex = (this.currentAttackIndex + 1) % numAttacks;
		}
	}
}
